/**
 * 根据共同的配置修改或者直接自定义个性化的配置
 */

import {
  commonProtoConfig,
  defaultChartOptions,
} from '@/components/common/VisualizationComp/ChartConfig/common'
import { cloneDeep } from 'lodash'

const {
  titleConfig,
  legendConfig,
  tooltipConfig,
  xAxis,
  yAxis,
  // layoutConfig,
  legendBasicColorConfig,
} = commonProtoConfig

const disableProtoConfig = new Set(['yAxisMax', 'yAxisMin'])
const copyYAxis = cloneDeep(yAxis)
copyYAxis.forEach((item) => {
  item.children = item.children.filter(
    (child) => !disableProtoConfig.has(child.name)
  )
})

const copyLegendColor = cloneDeep(legendBasicColorConfig)
copyLegendColor[0].props.options.push({
  label: 'bubble',
  type: 'discrete',
  value: ['#ff0000', '#0000ff'],
})

export const protoConfig = [
  {
    label: '',
    type: 'property',
    children: [
      ...titleConfig,
      ...xAxis,
      ...copyYAxis,
      {
        type: 'group',
        label: '热力配置',
        children: [
          {
            type: 'select',
            label: '热力形状',
            name: 'shape',
            defaultValue: 'square',
            props: {
              options: [
                {
                  label: '正方形',
                  value: 'square',
                },
                {
                  label: '矩形',
                  value: 'rect',
                },
                {
                  label: '圆形',
                  value: 'circle',
                },
              ],
            },
          },
          {
            type: 'simpleColumnSelect',
            label: '大小维度',
            name: 'sizeField',
            defaultValue: null,
            props: {
              filterColsType: 'number',
            },
          },
        ],
      },
      {
        type: 'switch',
        label: '单色显示',
        name: 'singleColor',
        defaultValue: true,
      },
      ...legendConfig,
      ...tooltipConfig,
      // ...layoutConfig,
      ...copyLegendColor,
    ],
    interaction: [
      {
        trigger: 'itemChange',
        when: {
          key: 'shape',
          operation: 'eq',
          value: 'rect',
        },
        actions: [
          {
            type: 'setVisible',
            key: 'sizeField',
            value: false,
          },
        ],
      },
    ],
  },
]
/**
 * 图表渲染的默认配置
 */
export const defaultOptions = {
  ...defaultChartOptions,
}
